package com.stary.mybatisplus.generator.typeconvert;

import com.baomidou.mybatisplus.generator.config.ITypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
/**
 * <p>自定义oracle类型转换 更改NUMBER类型 默认转换为Integer </p>
 * @author stary
 * @date 2018年6月6日 上午10:45:15
 */
public class CustomOracleTypeConvert implements ITypeConvert {
	@Override
	public DbColumnType processTypeConvert(String fieldType) {
		 String t = fieldType.toUpperCase();
	        if (t.contains("CHAR")) {
	            return DbColumnType.STRING;
	        } else if (t.contains("DATE") || t.contains("TIMESTAMP")) {
	            return DbColumnType.DATE;
	        } else if (t.contains("NUMBER")) {
	            if (t.matches("NUMBER\\(+\\d\\)")) {
	                return DbColumnType.INTEGER;
	            } else if (t.matches("NUMBER\\(+\\d{2}+\\)")) {
	                return DbColumnType.LONG;
	            }
	            return DbColumnType.INTEGER; // 默认 Integer
	        } else if (t.contains("FLOAT")) {
	            return DbColumnType.FLOAT;
	        } else if (t.contains("clob")) {
	            return DbColumnType.CLOB;
	        } else if (t.contains("BLOB")) {
	            return DbColumnType.OBJECT;
	        } else if (t.contains("binary")) {
	            return DbColumnType.BYTE_ARRAY;
	        } else if (t.contains("RAW")) {
	            return DbColumnType.BYTE_ARRAY;
	        }
	        return DbColumnType.STRING;
	}

}
